'use strict';

const Hapi = require('@hapi/hapi');
const handler = require('./Handler')
const {server} = require('./sqlApi')
const port = 3000
const init = async () => {

    const server = Hapi.server({
        port: port,
        host: '0.0.0.0'
    });
    server.route({
        method: 'GET',
        path: '/',
        handler: async (request, h) => {
            return await handler.get(request)
        }
    });

    server.route({
        method: 'POST',
        path: '/',
        handler: async (request, h) => {
            return await handler.post(request)
        }
    });

    await server.start();
    console.log('Server running on %s', server.info.uri);
};

process.on('unhandledRejection', (err) => {

    console.log(err);
    process.exit(1);
});
server()
init();

